﻿@namespace CodeManDesktopBlazor.BlazorComponents.Pages.codeTemple
@typeparam K
@typeparam T

@{
	var className = $"{Model.classGenDTO.Name.ToLower().ToTitleCase()}ToDB";
	var entityName = Model.classGenDTO.Name.ToTitleCase();
	string keyList = !Model.classAttributeDTOLst.HasItem() ? "" : Model.classAttributeDTOLst.Where(a => a.IsKey.IsNotNullOrWhiteSpace()).Select(a => a.AName).Aggregate((a, b) => a + "," + b);
	string nokeyList = !Model.classAttributeDTOLst.HasItem() ? "" : Model.classAttributeDTOLst.Where(a => a.IsKey.IsNullOrEmpty()).Select(a => a.AName).Aggregate((a, b) => a + "," + b);
}

<div class="div-code">
	<p class="p-n">
		using System;
		using System.ComponentModel;
	</p>
	<br />
	@if (!Model.classGenDTO.Namespace.IsNullOrEmpty())
	{
		<p class="p-n">namespace @Model.classGenDTO.Namespace</p>
		<p class="p-n">{</p>
	}
	@if (!Model.classGenDTO.Desc.IsNullOrEmpty())
	{
		<p class="p-c">@("\n")/// @("<summary>")</p>
		<p class="p-c">/// @Model.classGenDTO.Desc</p>
		<p class="p-c">/// @("<summary>\n")</p>
	}
	<p class="p-c"> public class @className</p>
	<p class="p-c">{</p>
	#region 参数
	<p class="p-c"> public const string TableName = "[@Model.classGenDTO.Name]"; </p>
	#endregion
	<p class="p-c">@("\n")</p>
	#region 属性
	@foreach (var item in Model.classAttributeDTOLst)
	{
		@if (!item.ADesc.IsNullOrEmpty())
		{
			<p class="p-a">@("\n")/// @("<summary>")</p>
			<p class="p-a">/// @item.ADesc</p>
			<p class="p-a">/// @("<summary>\n")</p>
		}
		else
		{
			@("\n")
		}
		<p class="p-a">public @(item.AType == AttrTypeEnum.cchar?AttrTypeEnum.sssbyte.GetDescription():item.AType.GetDescription()) @AttrTemplate(item) { get; set; }</p>
	}
	#endregion
	<p class="p-c">@("\n")</p>
	#region 公共方法

	<p class="p-a">@("\n")</p>
	<p class="p-c"> public string GetTableName() </p>
	<p class="p-c">{</p>
	<p class="p-c"> return "@className".TableName;</p>
	<p class="p-a">}</p>

	<p class="p-a">@("\n")</p>
	<p class="p-c"> public string GetKeys() </p>
	<p class="p-c">{</p>
	<p class="p-c"> return String.Intern("@keyList");</p>
	<p class="p-a">}</p>

	<p class="p-a">@("\n")</p>
	<p class="p-c"> public string GetAllUpdateCols()</p>
	<p class="p-c">{</p>
	<p class="p-len"> return String.Intern("@nokeyList");</p>
	<p class="p-a">}</p>

	<p class="p-a">@("\n")</p>
	<p class="p-c"> public string GetAllCols()</p>
	<p class="p-c">{</p>
	<p class="p-len"> return String.Intern(GetKeys() + "," + GetAllUpdateCols());</p>
	<p class="p-a">}</p>

	<p class="p-a">@("\n")public void CopyByEntity(@Model.classGenDTO.Name.ToTitleCase() m)</p>
	<p class="p-a">{@("\n")</p>
	@foreach (var item in Model.classAttributeDTOLst)
	{
		<p class="p-a-a">this.@item.AName=m.@item.AName.ToSplitCaseAB();@("\n")</p>
	}
	<p class="p-a">}@("\n")</p>

	<p class="p-a">@("\n")public @className GetDBEntity(@Model.classGenDTO.Name.ToTitleCase() m)</p>
	<p class="p-a">{@("\n")</p>
	<p class="p-a-a"> @className curr=new @(className)();@("\n")</p>
	@foreach (var item in Model.classAttributeDTOLst)
	{
		<p class="p-a-a">curr.@item.AName=m.@item.AName.ToSplitCaseAB();@("\n")</p>
	}
	<p class="p-a-a"> return curr;</p>
	<p class="p-a">}@("\n")</p>

	<p class="p-a">@("\n")public @entityName GetDBToEntity(@className m)</p>
	<p class="p-a">{@("\n")</p>
	<p class="p-a-a"> @entityName curr=new @(entityName)();@("\n")</p>
	@foreach (var item in Model.classAttributeDTOLst)
	{
		<p class="p-a-a">curr.@item.AName.ToSplitCaseAB()=m.@item.AName;@("\n")</p>
	}
	<p class="p-a-a"> return curr;</p>
	<p class="p-a">}@("\n")</p>

	#endregion
	<p class="p-c">}@("\n")</p>
	@if (!Model.classGenDTO.Namespace.IsNullOrEmpty())
	{
		<p class="p-n">}</p>
	}


</div>

